home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / HASWIN / HASWIN3 / _files / _haswin / WINDOWFI._c < prev    next >
Text File  |  1991-05-27  |  7KB  |  231 lines

  1. /* > $.CLIB.C.findwindow
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *       Routines to finds windows given things.
  21.  */
  22. #include "includes.h"
  23.  
  24. /*
  25.  *      given a window handle find the window structure associated with it.
  26.  */
  27. window *haswin_findwindowhandle(int handle) {
  28.  
  29.         register window  *wptr;
  30.  
  31.         if (handle <= 0)
  32.                 return((window *)handle);
  33.         for (wptr=haswin_topwindow; wptr; wptr=wptr->next) {
  34.                 if (wptr->handle == handle)
  35.                         return(wptr);
  36.         }
  37.         return((window *)0);
  38. }
  39.  
  40. /*
  41.  *      given a window structure, return the title of the window.
  42.  */
  43. char *haswin_getwindowtitle(window *wptr) {
  44.  
  45.         int     i;
  46.  
  47.         i = (int)wptr;
  48.         switch (i) {
  49.         case -1:
  50.                 return("Background");
  51.                 break;
  52.         case -2:
  53.                 return("Icon Bar");
  54.                 break;
  55.         case 0:
  56.                 return("Don't know");
  57.                 break;
  58.         default:
  59.                 if (wptr->win) {
  60.                         i = ((int *)wptr->win)[18];
  61.                         return((char *)i);
  62.                 } else
  63.                         return("don't know");
  64.                 break;
  65.         }
  66. }
  67.  
  68. /*
  69.  *      given a window structure, return the name of the window.
  70.  */
  71. char *haswin_getwindowname(window *wptr) {
  72.  
  73.         int     i;
  74.  
  75.         i = (int)wptr;
  76.         switch (i) {
  77.         case -1:
  78.                 return("Background");
  79.                 break;
  80.         case -2:
  81.                 return("Icon Bar");
  82.                 break;
  83.         case 0:
  84.                 return("Don't know");
  85.                 break;
  86.         default:
  87.                 return(wptr->name);
  88.                 break;
  89.         }
  90. }
  91.  
  92. /*
  93.  *      given a window name find the window structure associated with it.
  94.  */
  95. window *haswin_findwindowname(char *name) {
  96.  
  97.         register window  *wptr;
  98.         int              length;
  99.  
  100.         if (name) {
  101.                 length = asciilen(name);
  102.                 for (wptr=haswin_topwindow; wptr; wptr=wptr->next) {
  103.                         if (!strncmp(name, haswin_getwindowname(wptr), length))
  104.                                 return(wptr);
  105.                 }
  106.         }
  107.         return((window *)0);
  108. }
  109.  
  110. /*
  111.  *      given a window handle find the master window associated with it.
  112.  */
  113. window *haswin_findmasterhandle(int handle) {
  114.  
  115.         register window  *wptr;
  116.  
  117.         wptr = haswin_findwindowhandle(handle);
  118.         if ((int)wptr > 0)
  119.                 return(wptr->master);
  120.         else
  121.                 return(wptr);
  122. }
  123.  
  124. /*
  125.  *      given a window structure find the master window associated with it.
  126.  */
  127. window *haswin_findmasterwindow(window *win) {
  128.  
  129.         if ((int)win <= 0)
  130.                 return(0);
  131.         return(win->master);
  132. }
  133.  
  134. /*
  135.  *      this routine scans all the windows and returns a list of their
  136.  *      WIMP window handles.
  137.  *      1)      Create a small window.
  138.  *      2)      Open it at the back and off the screen.
  139.  *      3)      Use Get_window_state to get the handle of the one in front
  140.  *      4)      Record this in given buffer "list".
  141.  *      5)      Repeat 3/4 until handle is -1 or length is exceeded.
  142.  *      6)      Remove small window.
  143.  *      7)      Return number of windows
  144.  */
  145. int haswin_findallwindows(int *list, int length) {
  146.         window                  *win;
  147.         buffer                  buff;
  148.         _kernel_swi_regs        regs;
  149.         register int            i;
  150.  
  151.         if ((!list) || (length <= 0))
  152.                 return(HASWIN_FALSE);
  153.         win = haswin_makewindow("tmp",100,100,0,0,0,0,WINDOW_TRESPASS);
  154.         if (!win)
  155.                 return(HASWIN_FALSE);
  156.         haswin_openwindow(win, -200, 200, 100, 300, 0, 0, -2);
  157.         i = 0;
  158.         buff.i[0] = win->handle;
  159.         do {
  160.                 regs.r[1] = (int)&buff;
  161.                 haswin_swi(HASWIN_Get_window_state, ®s);
  162.                 list[i++] = buff.i[0] = buff.i[7];
  163.         } while ((i < length) && (buff.i[7] != -1));
  164.         haswin_deletewindow(win);
  165.         return(i-2);
  166. }
  167.  
  168. /*
  169.  *      these routines maintain the active windows lists.  If a window is
  170.  *      not in the active list then it will not be processed by HASWIN poll
  171.  *      routines in any way, but will be passed to any user poll routine.
  172.  */
  173.  
  174. /*
  175.  *      search the active windows list for a window handle "whandle"
  176.  *      NB: the iconbar windows (whandle < 0) are always in the active list.
  177.  *          the null window (whandle == 0) cannot be in the active list.
  178.  *          if there is nothing in the activelist then ALL windows are in
  179.  *          the active list by default.  This means that HASWIN does not
  180.  *          have to search the list each time if it is empty, and the default
  181.  *          action is to process ALL windows.
  182.  */
  183. int haswin_inactivelist(int whandle) {
  184.  
  185.         register int    i;
  186.  
  187.         if ((haswin_activewindowmax == 0) || (whandle < 0))
  188.                 return(HASWIN_TRUE);
  189.         if (whandle == 0)
  190.                 return(HASWIN_FALSE);
  191.         for (i=0; i<haswin_activewindowmax; i++) {
  192.                 if (haswin_activewindow[i] == whandle)
  193.                         return(HASWIN_TRUE);
  194.         }
  195.         return(HASWIN_FALSE);
  196. }
  197.  
  198. /*
  199.  *      add a new window to the active list.
  200.  */
  201. int haswin_addactivelist(int whandle) {
  202.  
  203.         if ((whandle <= 0) || (haswin_activewindowmax == HASWIN_ACTIVEMAX-1))
  204.                 return(HASWIN_FALSE);
  205.         haswin_activewindow[haswin_activewindowmax++] = whandle;
  206.         return(HASWIN_TRUE);
  207. }
  208.  
  209. /*
  210.  *      remove a window from the active list
  211.  */
  212. int haswin_removeactivelist(int whandle) {
  213.  
  214.         register int    i;
  215.  
  216.         if ((whandle <= 0) || (haswin_activewindowmax == 0))
  217.                 return(HASWIN_FALSE);
  218.         for (i=0; i<haswin_activewindowmax; i++) {
  219.                 if (haswin_activewindow[i] == whandle) {
  220.                         haswin_activewindowmax--;
  221.                         while (i<haswin_activewindowmax) {
  222.                                 haswin_activewindow[i] = haswin_activewindow[i+1];
  223.                                 i++;
  224.                         }
  225.                         return(HASWIN_TRUE);
  226.                 }
  227.         }
  228.         return(HASWIN_FALSE);
  229. }
  230.  
  231.